#include <sys/utsname.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/param.h>
#include <unistd.h>
#include <errno.h>
#define err_exit(MSG) (perror(MSG), exit(-1))
/*
*********************函数功能：获取系统信息*************************
*/
void main()
{
    struct utsname uts;            //定义系统信息结构体变量
    char hostname[MAXHOSTNAMELEN]; //定义主机名变量
    size_t size = MAXHOSTNAMELEN;  //定义主机最大长度
    //获取主机名
    if (gethostname(hostname, size) != 0)
        err_exit("cannot get hostname!\n");
    printf("hostname : %s\n", hostname);
    //获取系统信息
    if (uname(&uts) < 0)
        err_exit("cannot get machine information!\n");
    //输出系统信息
    printf("System is %s on %s hardware.\n", uts.sysname, uts.machine);
    printf("Nodename is %s.\n", uts.nodename);
    printf("Release is %s,Version is %s.\n", uts.release, uts.version);
    exit(0);
}